<%@ page contentType="text/html;charset=UTF-8" %>
<%--顶部导航--%>
<div class="header-title clear">
    <span class="zd-left">
        <img style="width: 50px;" src="<s:url value="/assets/web/img/logo.png"></s:url>" alt="图片加载中">
        重大项目节点管理系统
    </span>
    <span hidden id="user_phone">${user.phone}</span>
    <div id="username-right" class="dropdown username-right">
        <button id="username-right-btn" type="button" class=" dropdown-toggle" id="dropdownMenu2"
                data-toggle="dropdown" style="height: 28px;">
            <img style="width: 28px;" src="<s:url value="/assets/web/img/user.png"></s:url>"
                 alt="图片加载中">&nbsp;&nbsp;&nbsp;${user.name}
        </button>
        <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
            <li role="presentation">
                <a id="editPwd" class="change-password" data-toggle="modal" data-target="#myModal-change"
                   role="menuitem" tabindex="-1" href="#">修改密码</a>
            </li>
            <li role="presentation" class="divider"></li>
            <li role="presentation">
                <a role="menuitem" tabindex="-1" href="/newlogin/exit">退出登录</a>
            </li>
        </ul>
    </div>


    <div id="myperson" class="dropdown  index-charts">
        <button type="button" class="btn dropdown-toggle" id="dropdownMenu1"
                data-toggle="dropdown" style="width:auto;">
            <img src="<s:url value="/assets/web/img/lingdang.png"></s:url>" alt="图片加载中">
            我的消息
            <span class="badge  pull-right reds"
                  style="margin:0 5px;background-color: #d15b47 !important; margin-top: 2px;">${myTaskNum + quetionNum + nodeCount}</span>
        </button>
        <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
            <li class="clearfix" role="presentation">
                <a class="pull-left" role="menuitem" tabindex="-1" href="/missions">我的督查</a>
                <span class="badge pull-right reds"
                      style="background-color: #d15b47 !important; margin-right: 17px; margin-top: 4px;">${myTaskNum}</span>
            </li>
            <li class="clearfix" role="presentation">
                <a class="pull-left" role="menuitem" tabindex="-1" href="/qestionReport">我的协调</a>
                <span class="badge  pull-right reds"
                      style="background-color: #d15b47 !important; margin-right: 17px; margin-top: 4px;">${quetionNum}</span>
            </li>
            <c:if test="${user.branchType=='0'}">
                <li class="clearfix" role="presentation">
                    <a class="pull-left" role="menuitem" tabindex="-1" href="/missions">待办任务</a>
                    <span class="badge pull-right reds"
                          style="background-color: #d15b47 !important; margin-right: 17px; margin-top: 4px;">${nodeCount}</span>
                </li>
            </c:if>
            <c:if test="${user.branchType=='1'}">
                <li class="clearfix" role="presentation">
                    <a class="pull-left" role="menuitem" tabindex="-1" href="/accAudit/go/list">待办任务</a>
                    <span class="badge pull-right reds"
                          style="background-color: #d15b47 !important; margin-right: 17px; margin-top: 4px;">${nodeCount}</span>
                </li>
            </c:if>

        </ul>
    </div>


    <a class="homePage" href="<s:url value="/newlogin/goIndex"></s:url>">首页 </a>


</div>
<%--修改密码模态框--%>
<div class="modal fade" id="myModal-change" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog" style="z-index: 9999999;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel" style="font-weight: 600;">个人密码信息修改</h4>
            </div>
            <div class="modal-body">
                <form id="defaultForm" method="post" action="" class="form-horizontal">

                    <div class="form-group">
                        <label class="col-lg-3 control-label" for="username">登录账号</label>
                        <div class="col-lg-5">
                            <input type="text" id="username" readonly="readonly" class="form-control" name="username"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-3 control-label" for="password">原密码</label>
                        <div class="col-lg-5">
                            <input type="text" id="password" class="form-control" name="password"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-lg-3 control-label" for="newPwd">新密码</label>
                        <div class="col-lg-5">
                            <input type="password" id="newPwd" class="form-control" name="newPwd"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-lg-3 control-label" for="reNewPwd">确认密码</label>
                        <div class="col-lg-5">
                            <input type="password" id="reNewPwd" class="form-control" name="reNewPwd"/>
                        </div>
                    </div>

                    <div class="modal-footer">
                        <button type="button" id="close-modal" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-primary" id="edit">提交</button>
                    </div>
                </form>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<script src="<s:url value="/assets/web/common/bootstrapvalidator/vendor/jquery/jquery.min.js"></s:url>"></script>
<script src="<s:url value="/assets/web/common/bootstrapvalidator/dist/js/bootstrapValidator.js"></s:url>"></script>
<script>
    $(function () {
        $('#defaultForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                password: {
                    message: '密码无效',
                    validators: {
                        notEmpty: {
                            message: '原密码是必需的，不能为空'
                        },
                        stringLength: {
                            min: 6,
                            max: 30,
                            message: '原密码必须超过6个字符，长度不能超过30个字符'
                        },
                        remote: {
                            type: 'POST',   //请求方式
                            url: '/newlogin/check',
                            data: function () {
                                return {
                                    username: $("#username").val(),
                                    password: $("#password").val()
                                };
                            },
                            delay: 300,	//（默认输入一个字符，提交一次，服务器压力太大）
                            message: '原密码错误'
                        }
                    }
                },
                newPwd: {
                    validators: {
                        notEmpty: {
                            message: '新密码不能为空'
                        },
                        stringLength: {
                            min: 6,
                            max: 30,
                            message: '新密码必须超过6个字符，长度不能超过30个字符'
                        }
                    }
                },
                reNewPwd: {
                    validators: {
                        notEmpty: {
                            message: '确认密码不能为空'
                        },
                        identical: {
                            field: 'newPwd',
                            message: '确认密码及其新密码不一致'
                        },
                        stringLength: {
                            min: 6,
                            max: 30,
                            message: '确认密码必须超过6个字符，长度不能超过30个字符'
                        }
                    }
                }
            }
        });
        //清空
        $('#close-modal').click(function () {

            $('#defaultForm').data('bootstrapValidator').resetForm(true);//清理验证
        })

        //提交
        $("#edit").click(function () {
            var flag = $('#defaultForm').data("bootstrapValidator").isValid();
            // var demo = $("#defaultForm").serialize();
            var username = $("#username").val();
            var password = $("#password").val();
            var newPwd = $("#newPwd").val();
            var reNewPwd = $("#reNewPwd").val();
            if (flag) {
                $.ajax({
                    type: "POST",
                    url: "/newlogin/editPwd",
                    dataType: "json",
                    data: {
                        username: username,
                        password: password,
                        newPwd: newPwd,
                        reNewPwd: reNewPwd
                    },
                    success: function (res) {
                        if (res.code == '200') {
                            if (res.data == '0') {
                                alert(res.message);
                            } else {
                                alert(res.message);
                                location.reload();
                            }
                        } else {
                            alert("未知错误");
                        }
                    }
                })
            }
        })


        /**
         * 修改密码按钮，点击事件
         */
        $("#editPwd").click(function () {
            var username = $("#user_phone").html();
            $("#username").val(username);
        })

    })
</script>